package com.pactera.miyuangroup.service.impl;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.baomidou.mybatisplus.plugins.pagination.Pagination;
import com.pactera.miyuangroup.common.Constants;
import com.pactera.miyuangroup.db.entity.EquipmentAudit;
import com.pactera.miyuangroup.db.mapper.EquipmentAuditMapper;
import com.pactera.miyuangroup.service.EquipmentAuditService;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.pactera.miyuangroup.vo.request.web.PageVenderCodifyAuditReq;
import com.pactera.miyuangroup.vo.response.web.PageVenderCodifyAuditRes;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 设备信息修改审核 服务实现类
 * </p>
 *
 * @author WangWu
 * @since 2018-04-13
 */
@Service
public class EquipmentAuditServiceImp extends ServiceImpl<EquipmentAuditMapper, EquipmentAudit> implements EquipmentAuditService {

    @Override
    public Page<PageVenderCodifyAuditRes> selectListPage(PageVenderCodifyAuditReq req,String org) {

        //条件构造器
        EntityWrapper wrapper = new EntityWrapper();

        //organization_id
        if (!Constants.SYS_ROOT.equals(org)) {
            wrapper.eq("organization_id", org);
        }
        //编号
        if (StringUtils.isNotBlank(req.getNumber())) {
            wrapper.eq("numbers", req.getNumber());
        }


        //提交时间
        if (StringUtils.isNotBlank(req.getStartTime())) {
            wrapper.ge("add_time", req.getStartTime());
        }

        //提交时间
        if (StringUtils.isNotBlank(req.getEndTime())) {
            wrapper.lt("add_time", req.getEndTime());
        }

        //司员编号
        if (StringUtils.isNotBlank(req.getJobumber())) {
            wrapper.eq("job_number", req.getJobumber());
        }

        //司员姓名
        if (StringUtils.isNotBlank(req.getJobumber())) {
            wrapper.like("name", req.getName());
        }
        //联系方式
        if (StringUtils.isNotBlank(req.getPhone())) {
            wrapper.eq("phone", "");
        }

        //分页数据
        Page<PageVenderCodifyAuditRes> pageVenderCodifyAuditRes = new Page<PageVenderCodifyAuditRes>(req.getCurrent(), req.getSize());
        List<PageVenderCodifyAuditRes> venderCodifyAuditRes = baseMapper.selectListRelationUser(pageVenderCodifyAuditRes, wrapper);
        //分页
        pageVenderCodifyAuditRes.setRecords(venderCodifyAuditRes);
        return pageVenderCodifyAuditRes;
    }
}
